package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList booklist) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要删除的书籍名:");
        String name = sc.nextLine();

        int currentSize = booklist.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book temp = booklist.getBook(i);
            if(temp.getName().equals(name)){
                for (int j = i; j < currentSize-1; j++) {
                    booklist.setBook(j,booklist.getBook(j+1));
                }
                booklist.setUsedSize(currentSize - 1);
                booklist.setBook(currentSize - 1 , null);
                break;
            }
        }
    }
}
